<!DOCTYPE html>
<html>
<head>
    <title>1</title>
</head>
<style>
    button{
        margin: 5px;
    }
</style>
<body>
<div>
    <label>Number A:<input id="radio-a" type="radio" name="math-obj" value="a" checked><input id="num-a" type="text" value=""></label>
    <label>Number B:<input id="radio-b" type="radio" name="math-obj" value="b"><input id="num-b" type="text" value=""></label>
</div>
<div id="buttons">
    <button>判断当前选中的输入框输入内容是否为数字</button>
    <button>把 A 四舍五入为 B 个小数位数的数字</button>
    <button>当前选中数字的绝对值</button>
    <button>对当前选中的数字进行上舍入</button>
    <button>对当前选中的数字进行下舍入</button>
    <button>把当前选中的数字四舍五入为最接近的整数</button>
    <button>返回 A 和 B 中的最高值</button>
    <button>返回 A 和 B 中的最低值</button>        
</div>
<p id="result"></p>

<script>
    var buts = document.getElementById("buttons").querySelectorAll("button");
    var radioA = document.getElementById("radio-a");
    var radioB = document.getElementById("radio-b");
    var numA = document.getElementById("num-a");
    var numB = document.getElementById("num-b");
    var p = document.getElementById("result");
    var num;
    var flag;
    function whichone(){
        if(radioA.checked)
            num = numA;
        else
            num = numB;
            if(isNaN(num.value) || num.value == ""){
                console.log("输!入!数!字!");
                flag = false;
            }
        }
    buts[0].onclick = function(){
        if(radioA.checked)
            num = numA;
        else
            num = numB;
        if(!isNaN(num.value))
            console.log("是数字");
        else
            console.log("不是数字");
    }
    buts[1].onclick = function(){
        if(isNaN(numA.value) || isNaN(numB.value) || numA.value == "" || numB.value == ""){
            console.log("不好好的输入数字就不给你算~");
            return;
        }
        p.textContent = Number(numA.value).toFixed(Number(numB.value));
    }
    buts[2].onclick = function(){
        whichone();
        if(!flag)
            return;
        p.textContent = Math.abs(Number(num.value));
    }
    buts[3].onclick = function(){
        whichone();
        if(!flag)
            return;
        p.textContent = Math.ceil(Number(num.value));
    }
    buts[4].onclick = function(){
        whichone();
        if(!flag)
            return;
        p.textContent = Math.floor(Number(num.value));
    }
    buts[5].onclick = function(){
        whichone();
        if(!flag)
            return;
        p.textContent = Math.round(Number(num.value));
    }
    buts[6].onclick = function(){
        if(isNaN(numA.value) || isNaN(numB.value) || numA.value == "" || numB.value == ""){
            console.log("不好好的输入数字就不给你算~");
            return;
        }
        var a = Number(numA.value);
        var b = Number(numB.value);
        p.textContent = a>b?a:b;
    }
    buts[7].onclick = function(){
        if(isNaN(numA.value) || isNaN(numB.value) || numA.value == "" || numB.value == ""){
            console.log("不好好的输入数字就不给你算~");
            return;
        }
        var a = Number(numA.value);
        var b = Number(numB.value);
        p.textContent = a<b?a:b;
    }
</script>
</body>
</html>